2. Use trained model in Android

In previous chapter, we discussed how to train an object classifier using our own images. At the end, we got trained model and labels file (retrained_graph.pb, retrained_labels.txt).

In this chapter, We are going to load pre-trained classifer in our own Android app. Unfortunately, we can not use trained model in Android directly. We need to optimize it using a tool, namely "optimize_for_inference", provided by Tensorflow.


1. Build tool "optimize_for_inference"


2. Optimize trained model

Let's assume that our pre-trained model is <folder_path>/retrained_graph.pb. Then, we can use the following command to optimize the model and save it as <folder_path>/retrained_graph_android.pb

bazel-bin/tensorflow/python/tools/optimize_for_inference \
--input=<folder_path>/retrained_graph.pb \
--output=<folder_path>/retrained_graph_android.pb \
--input_names=Mul \
--output_names=final_result

3. Modify Tensorflow Android Demo


Next: 3. Drone_setup, Previous: 1. How to train an object classifier using our own images, Up: Index